﻿using Microsoft.Xna.Framework;

namespace Firefly.ExtensionMethods
{
    public static class Vector3Extensions
    {
        public static Vector3 Parse(this Vector3 obj, string value)
        {
            string[] split = value.Split(',');

            if (split != null && split.Length == 3)
            {
                return new Vector3(float.Parse(split[0]), float.Parse(split[1]), float.Parse(split[2]));
            }

            return Vector3.Zero;
        }

        public static Vector3 Inverse(this Vector3 obj)
        {
            return new Vector3(-obj.X, -obj.Y, -obj.Z);
        }

        public static Vector3 GetDirection(this Vector3 obj, Vector3 destination)
        {
            Vector3 direction = destination - obj;
            direction.Normalize();
            return direction;
        }

        public static Matrix ToRotation(this Vector3 obj)
        {
            return Matrix.CreateFromYawPitchRoll(obj.X, obj.Y, obj.Z);
        }

        public static Vector4 ToVector4(this Vector3 obj)
        {
            return new Vector4(obj.X, obj.Y, obj.Z, 1.0f);
        }
    }
}